import getvalue2
import  wxchat;
import tkinter as tk
import argparse
from PIL import Image
import time
import os
from datetime import datetime
import uuid
import addnodetofile
import merergimage;

from PIL import Image, ImageDraw, ImageFont






def generate_random_id():
    # 生成一个 UUID
    random_uuid = uuid.uuid4()
    # 将 UUID 转换为十六进制字符串并取前 16 位
    return random_uuid.hex[:16]


parser = argparse.ArgumentParser(description='处理图片及相关信息的脚本')
parser.add_argument('-imagepath', type=str, required=True, help='图片的路径')
parser.add_argument('-msg', type=str, required=True, help='用户的输入信息')

args = parser.parse_args()
image_path = args.imagepath
user_msg = args.msg



# 笔记文件夹
wikipath="E:\\wiki\\wikiob\\a2\\全新"

dic={
    'beforewidth':0,
    "beforeinput":"",
    "windowroot":None
    }

save_folder = f"{wikipath}\\_files"
if not os.path.exists(save_folder):
    os.makedirs(save_folder)

##.py

print('image_path===>',image_path)
img = Image.open(image_path)
getvalue2.setvalue2txt(user_msg)

# 发送 qiniu
# uploaded_image_url=wxchat.sendImage2qiniu(img)
# 发送到文档笔记
print('------------发送到文档笔记-----------------')
# list1 = user_msg.split('#')
# list2 = [s for s in list1 if s.strip()]
# firsttag = list2[0]
# # 获取第一个 然后附件名称.canvas保存起来
# file_name = 'hebin_'+str(int(time.time())) + ".png"
# file_path = os.path.join(save_folder, file_name)
# img.save(file_path)
# print(f"已成功将图片保存到 {file_path}")
#
# tagstr = f"{user_msg}#{datetime.now().strftime('%Y年%m月%d日')}"
# markdown=f"{tagstr}\n![图片]({uploaded_image_url})\n\n\n"
# # 设置 md
# getvalue2.setvalue2txt(markdown,r'E:\home\blog\pycut2\Image-recognition-enters-the-whiteboard\_setuserinputandimg.txt')
tagstr = f"{user_msg}#{datetime.now().strftime('%m月%d日')}"
# merergimage_path
merergimage_path=merergimage.textandimage(tagstr,img)
print('最后合并的图片',merergimage_path)
# 设置 最后合并的图片
getvalue2.setvalue2txt(merergimage_path,r'E:\home\blog\pycut2\Image-recognition-enters-the-whiteboard\_merergimage_path.txt')

